package com.myz.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author maoyz on 18-4-9.
 */
public class ConnectionUtils {

    public static Connection getConnection() throws IOException, TimeoutException {
        //1 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //2 设置RabbitMQ相关信息
        // factory.setHost(ConnectionFactory.DEFAULT_HOST);
        factory.setHost("192.168.107.100");
        factory.setUsername("maoyz");
        factory.setPassword("123456");
        // AMQP端口号
        factory.setPort(ConnectionFactory.DEFAULT_AMQP_PORT);
        // 虚拟主机
        factory.setVirtualHost("/");
        // 3 创建一个新的连接
        return factory.newConnection();
    }
}
